﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nage.Algorithms.Evolution;
using Nage.Algorithms.Population;
using Nage.Algorithms.RandomGenerators;
using Nage.Examples.Rastrigin.Solution;

namespace Nage.Examples.Rastrigin.Evolution
{
    public class CoordinatesRecombination : ISolutionRecombination<Coordinates>
    {
        public Coordinates[] Recombine(Coordinates solutionA, Coordinates solutionB)
        {
            int dim = solutionA.Vector.Length;
            int divAmount = (int)Rng.GetInstance().GetDouble(dim);
            double[] childA = new double[dim];
            double[] childB = new double[dim];
            for (int i = 0; i < dim; i++)
            {
                if (i < divAmount)
                {
                    childA[i] = solutionA.Vector[i];
                    childB[i] = solutionB.Vector[i];
                }
                else
                {
                    childA[i] = solutionB.Vector[i];
                    childB[i] = solutionA.Vector[i];
                }
            }
            return new Coordinates[] { new Coordinates(childA), new Coordinates(childB) };
        }
    }
}
